{% extends 'admin/common/base.html' %}
{% block css %}
{{super()}}
<link href="{{url_for('admin.static',filename='ajax/libs/jasny/jasny-bootstrap.min.css')}}?v=3.1.3" rel="stylesheet"/>
<link href="{{url_for('admin.static',filename='ajax/libs/summernote/summernote.css')}}" rel="stylesheet"/>
<link href="{{url_for('admin.static',filename='ajax/libs/summernote/summernote-bs3.css')}}" rel="stylesheet"/>
{% endblock %}
{% block body %}
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form">
            <div class="form-group">
				<label class="col-sm-3 control-label is-required">参数名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="sname" id="sname" value="" required>
				</div>
			</div>
            <div class="form-group">
				<label class="col-sm-3 control-label is-required">参数键名(key)：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="skey" id="skey" value="" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">输入类型：</label>
				<div class="col-sm-8">
					<select class="form-control" id="col_type" name="col_type" required >
						<option value="string">文本</option>
						<option value="file">图片/文件</option>
						<option value="richtext">富文本</option>
					</select>
				</div>
			</div>
            <div class="form-group">
				<label class="col-sm-3 control-label is-required">参数键值(value)：</label>
				<div class="col-sm-8" id="input_type">
					<textarea class="form-control" name="svalue" id="svalue" value="" required></textarea>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control"></textarea>
				</div>
			</div>
			<!-- <div class="text-center" style="color:red;">**修改系统参数需要重启系统服务才能完全生效**</div> -->
		</form>
	</div>
</body>
{% endblock %}
{% block js %}
{{ super() }}
<script src="{{url_for('admin.static',filename='ajax/libs/jasny/jasny-bootstrap.min.js')}}?v=3.1.3"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/summernote/summernote.min.js')}}"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/summernote/summernote-zh-CN.js')}}"></script>
<script type="text/javascript">

	$(function(){
		$('#col_type').on('change', function(){
			if($(this).val() == 'file') { //文件输入类型
				var html = ' \
					<div class="fileinput fileinput-new input-group" data-provides="fileinput"> \
                        <div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div> \
                        <span class="input-group-addon btn btn-white btn-file"><span class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input type="file" name="svalue"></span> \
                        <a href="#" class="input-group-addon btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a> \
                    </div> \
				';
				$('#input_type').html(html);
			}else if($(this).val() == 'richtext') {
				var html = '<textarea class="form-control summernote" name="svalue" id="svalue" value="" required></textarea>';
				$('#input_type').html(html);
				$('.summernote').summernote({
					lang: 'zh-CN',
					callbacks: {
						onImageUpload: function(files) {
						//上传图片到服务器
						var formData = new FormData();
						formData.append('file',files[0]);
						$.modal.loading('图片上传中');
						$.ajax({
							url : "{{url_for('admin.upload')}}",//后台文件上传接口
							type : 'POST',
							data : formData,
							processData : false,
							contentType : false,
							success : function(resp) {
								$.modal.closeLoading();
								console.log(resp)
								$('.summernote').summernote('insertImage', resp.data,'');
							},
							complete: function(xhr,status) {
								$.modal.closeLoading();
							}
						});
					}
				},
				});
			}else {
				var html = '<textarea class="form-control" name="svalue" id="svalue" value="" required></textarea>';
				$('#input_type').html(html);
			}
		});
	});
    
    $("#form").validate({

    });
    
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save("{{url_for('admin.sys.setting.add')}}", new FormData(document.getElementById('form')));
        }
    }

</script>
{% endblock %}
